package jdbc;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * 聚合函数
 */
public class Demo7 {
    public static void main(String[] args) {
        try ( Connection connection = DBUtil.getConnection();){
            Statement statement = connection.createStatement();
            String sql = "SELECT COUNT(*) count ,AVG(salary) avg_sal " +
                            "FROM teacher";
            ResultSet rs = statement.executeQuery(sql);
            while (rs.next()){
                int count  = rs.getInt("count");
                double avgSal = rs.getDouble("avg_sal");
                System.out.println("一共："+count+"人，平均工资为："+avgSal);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
